package com.shujia.flink.window

import org.apache.flink.streaming.api.TimeCharacteristic
import org.apache.flink.streaming.api.scala._

object Demo3CountWindow {
  def main(args: Array[String]): Unit = {
    val env: StreamExecutionEnvironment = StreamExecutionEnvironment.getExecutionEnvironment

    env.setParallelism(1)

    //设置事件模式
    env.setStreamTimeCharacteristic(TimeCharacteristic.EventTime)

    val ds1: DataStream[String] = env.socketTextStream("master", 6666)

    val kvDS: DataStream[(String, Int)] = ds1
      .flatMap(_.split(","))
      .map((_, 1))

    /**
      * countWindow
      * 滑动和滚动
      *
      */

    kvDS.keyBy(_._1)
      .countWindow(10, 2)
      .sum(1)
      .print()


    env.execute()


  }
}
